package com.app.framework.Security;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;
 

@Service
public class UserService implements UserDetailsService {
    
  //  @Autowired
   // XtMapper rolesMapper;

    @Override
    public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
        User user = new User();// userMapper.selectByPrimaryKey(0);
        user.setUsername("admin");
        user.setPassword(DigestUtils.md5DigestAsHex("123456".toString().getBytes()));
        if (user == null) {
            //避免返回null，这里返回一个不含有任何值的User对象，在后期的密码比对过程中一样会验证失败
            return new User();
        }else
        {
        	List<GrantedAuthority> grantedAuthorities = new ArrayList<GrantedAuthority>();
 
			return new org.springframework.security.core.userdetails.User(user.getUsername(), user.getPassword().toString(),
					grantedAuthorities);
        }
        //查询用户的角色信息，并返回存入user中
       // List<Role> roles = rolesMapper.getRolesByUid(user.getId());
       // user.setRoles(roles);
       
    }
}
